Skip to content

Override css and js links - #1898

Merged
Conengmo merged 5 commits into
python-visualization:mainfrom
hansthen:1519_override_css_and_js
Apr 4, 2024
Merged

Conengmo merged 5 commits into
python-visualization:mainfrom
hansthen:1519_override_css_and_js

Conversation

@hansthen

@hansthen hansthen commented Mar 9, 2024 •

Copy link
Copy Markdown
Collaborator

Add a method to the JSCSSMixin that allows users to override a specific link to css or js. Unfortunately this still requires users to know the name of the of the link, which will require looking at the code or introspection.

Closes #1519

@hansthen hansthen mentioned this pull request Mar 12, 2024

@Conengmo Conengmo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Hans, thanks for helping out with this one! Your code looks good, but I want to challenge using another approach here.

Now there's one function with a switch parameter, that has some logic in it to switch based on that parameter. In my opinion this is a pattern that indicates two separate functions would be better suited. Here's an example to illustrate what I mean:

def add_js_link(name, url):
     self._add_link(name, url, self.default_js)

def add_css_link(name, url):
     self._add_link(name, url, self.default_css)

def _add_link(name, url, link_array):
    # add the link to the array

This way we don't need switching logic. And I think it's a bit more user friendly than having a switching parameter the user must learn how to use.

I'd also opt to not have a separate method to add multiple links. This is easy for users to do themselves, and less code for us to maintain.

To really close the ticket we also need to document this feature in our documentation. I'm thinking maybe a new page in the advanced guide?

@hansthen

hansthen commented Apr 3, 2024

Copy link
Copy Markdown
Collaborator Author

I updated the code as requested. As to the documentation, adding links for javascript and css is mostly useful for writing plugins. Regular use will not typically require this API. What would you think if we added a guide for plugin writers to the advanced documentation and add the documentation there?

@Conengmo

Conengmo commented Apr 4, 2024

Copy link
Copy Markdown
Member

I updated the code as requested.

Thanks!

As to the documentation, adding links for javascript and css is mostly useful for writing plugins. Regular use will not typically require this API.

I don't think that's true. We've had users ask for this feature so they can make self contained maps that use local resources only. Also, #1519 talks about his as a user from a Django context.

For developers we have our contribution guide, which has some guidelines on plugin development. I don't really see the link with this topic here.

I'm also fine with merging this and leaving the ticket open to add documentation in a later stage. What do you prefer?

Comment thread folium/elements.py Resolved
Comment thread folium/elements.py Resolved
@hansthen

hansthen commented Apr 4, 2024 •

Copy link
Copy Markdown
Collaborator Author

Yeah I see the other use cases now. I will add the documentation in this PR.

@Conengmo Conengmo changed the title Re: #1519 Override css and js links Override css and js links Apr 4, 2024
hansthen and others added 5 commits April 4, 2024 13:38
Add a method to the JSCSSMixin that allows users
to override a specific link to css or js. Unfortunately
this still requires users to know the name of the
of the link, which will require looking at the code
or introspection.
Also added a method to bulk add several links in one call.
Co-authored-by: Frank Anema <33519926+Conengmo@users.noreply.github.com>

@Conengmo Conengmo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for adding that documentation!

@Conengmo
Conengmo merged commit 5c2f3d1 into python-visualization:main Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The js/css override mechanism is not well explained in the docs

2 participants